<?php
// +----------------------------------------------------------------------
// |  [ MAKE YOUR WORK EASIER]
// +----------------------------------------------------------------------
// | Copyright (c) 2003-2016 http://www.nbcc.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: fangrenfu <fangrenfu@126.com>
// +----------------------------------------------------------------------

namespace app\param\controller;

use app\common\access\MyAccess;
use app\common\access\MyController;
use app\common\service\Teacher;
use app\common\vendor\PHPExcel;

class Team extends MyController
{
    //显示信息
    public function query($page=1,$rows=20,$teacherno = '%', $teachername= '%', $school = '',$team='C',$sort='teacherno',$order='')
    {
        $result = null;
        try {
            $obj = new \app\common\service\Team();
            $result = $obj->getList($page,$rows,$teacherno,$teachername,$school,$team,$sort,$order);


        } catch (\Exception $e) {
            MyAccess::throwException($e->getCode(), $e->getMessage());
        }
        return json($result);
    }

    //更新信息
    public function update()
    {
        $result = null;
        try {
            $obj = new \app\common\service\Team();
            $result = $obj->update($_POST);//无法用I('post.')获取二维数组

        } catch (\Exception $e) {
            MyAccess::throwException($e->getCode(), $e->getMessage());
        }
        return json($result);
    }

    //检索教师
    public function search($page=1,$rows=20,$teacherno='%',$teachername='%',$school=''){
        $result=null;
        try{
            $obj=new Teacher();
            $result=$obj->getList($page,$rows,$teacherno,$teachername,$school);
        }
        catch (\Exception $e) {
            MyAccess::throwException($e->getCode(),$e->getMessage());
        }
        return json($result);
    }


    public function export(){
        $result=null;
        try{
            $obj=new \app\common\service\Link();
            $teacherno=session("S_TEACHERNO");
            $result=$obj->getList(1,1000,'%','%','%','','','','studentno','',$teacherno);
            $data = $result['rows'];
            $file = "职业沟通成绩单";
            $sheet = '全部';
            $title = $file;
            $subtitle="教师：".session('S_TEACHER_NAME').'    时间：'.date('Y年m月d日   ',time()).'签字:________';
            $template = array("studentno" => "学号", "studentname" => "姓名","classname"=>"班级","schoolname"=>"学院", "score" => "成绩");
            $width=array("studentno" => 10, "studentname" =>10,"classname"=>20,"schoolname"=>31, "score" => 15);
            $string = array("studentno");
            $array[] = array("sheet" => $sheet, "title" => $title,"subtitle"=>$subtitle, "template" => $template, "data" => $data, "string" => $string,"width"=>$width);
            PHPExcel::export2Excel($file, $array);
        }
        catch (\Exception $e) {
            MyAccess::throwException($e->getCode(),$e->getMessage());
        }
        return json($result);
    }
} 